package com.xiaotu.spider.douban.pipeline;

import java.util.List;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.ShortCommentsModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

@Component("DouBanMovieSmallCommentPipeline")
public class DouBanMovieSmallCommentPipeline extends APipeline{

	@Override
	protected void doProcess(ResultItems resultItems, Task task) {
		List<ShortCommentsModel> shortCommentsModelList = resultItems.get(ShortCommentsModel.class.getName());
		if (shortCommentsModelList == null || shortCommentsModelList.size() == 0)
            return;
		String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.DOUBAN_MOVIE_SHORT_COMMENT_YYYYMMDD);
        for (ShortCommentsModel shortCommentsModel : shortCommentsModelList) {
        	cacheHandler.hSet(key, shortCommentsModel.getId(), shortCommentsModel);
        	cacheHandler.setCacheTimeout(key);
		}
	}
	
}
